package collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合只能存放引用类型元素,并且存放的就是元素的引用(地址)
 */
public class CollectonDemo3 {
    public static void main(String[] args) {
        Collection c=new ArrayList();
        Point p=new Point(1,2);
        c.add(p);//将p变量的值(地址)存入集合

        System.out.println("p:"+p);
        System.out.println("c"+c);

        p.setX(5);
        System.out.println("p:"+p);//5,2
        System.out.println("c"+c);//5,2

        doSome(p,c);
        System.out.println("p="+p);//5,2
        System.out.println("c="+c);//0
    }
    public static  void doSome(Point p,Collection c){
        p.setX(5);
        p=new Point(6,7);
        c.clear();
        c=new ArrayList();
        c.add(p);
    }
}
